<?PHP
/* Web Statistics and Analytics Console (PHP)
 *  subpages/user-login.php
 *  Author: Trevor Bidyk
 *  Created: January 1, 2000
 *  Last modified: April 4, 2011
 *   (C) Us 2011
 *   Uses Simple PHP Framework, licensed under the FreeBSD license.
 *    View license in ./include/LICENSE.
 *   All rights reserved.
 */

if (isset($_POST['SubmitButton']) && $_POST['SubmitButton']) {
    $Username = htmlspecialchars($_POST['UserUsername']);
    $Password = htmlspecialchars($_POST['UserPassword']);

    if ($Auth->login($_POST['UserUsername'], $_POST['UserPassword'])) {
        redirect(WEB_ROOT . 'index.php');
    } else {
        $Error->add('username', 'You have entered an incorrect username and password.');
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
        <title>Web Statistics and Analytics Console</title>
        <link href="style/style.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <div id="aac-header">
            <div id="interior">
                <div id="title"><span>Web Statistics and Analytics Console</span></div>
                <div id="current-time"><span><?php echo date("H:m F, j Y"); ?></span></div>
                <div id="current-user"><span>Not logged in.</span></div>

            </div>
        </div>
        <div id="aac-navigation"></div>
        <div id="content">
            <div id="aac-subnavigation"></div>
            <div style="text-align: center">
                <h2>Please login to continue</h2>
                <span>Please enter your username and password:</span><br />
                <br />
                <?php
                if (!$Error->ok()) {
                    echo '<div id="statspanel">';
                    echo "<span>$Error</span>";
                    echo '</div><br />';
                }
                ?>
                <form action="user.php?do=login" method="post">
                    <div style="text-align: center">
                        <span>
                            <label for="UserUsername">Username:</label>
                            <input type="text" name="UserUsername" value="<?php echo @$Username; ?>" id="UserUsername" />
                        </span>
                        <br />
                        <span>
                            <label for="UserPassword">Password:</label>
                            <input type="password" name="UserPassword" id="UserPassword" />
                        </span>
                        <br />
                        <br />
                        <input type="submit" name="SubmitButton" value="Login" id="SubmitButton" />
                    </div>
                </form>
            </div>
        </div>
    </body>
</html>